package com.zito.health.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zito.health.common.annotations.ResponseResult;
import com.zito.health.common.result.PageResult;
import com.zito.health.common.result.VerifyResult;
import com.zito.health.entity.Extension;
import com.zito.health.service.ExtensionService;
import com.zito.health.vo.ExtensionVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:
 * @author: Sam
 * @time: 2020/03/12 17:18
 */
@Slf4j
@ResponseResult
@RestController
@RequestMapping("/extension")
public class ExtensionController {

    @Autowired
    private ExtensionService extensionService;

    @GetMapping
    public PageResult list(Extension param, @RequestParam(defaultValue = "0") Integer pageNo, @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult<Extension> result = new PageResult();
        if(pageNo!=null&&pageSize!=null){
            PageHelper.startPage(pageNo, pageSize);
        }
        List<Extension> list = extensionService.queryList(param);
        PageInfo<Extension> pageInfo = new PageInfo<Extension>(list);
        result.setTotal(pageInfo.getTotal());
        result.setRows(pageInfo.getList());
        return result;
    }

    /**
     * 下拉列表用
     * @param param
     * @return
     */
    @GetMapping("/list")
    public List<Extension> list(Extension param){
        List<Extension> list = extensionService.query(param);
        return list;
    }
    /**
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Extension queryById(@PathVariable Integer id){
        Extension extension = extensionService.queryById(id);
        return extension;
    }

    @PostMapping
    public VerifyResult save( Extension extension) {
        VerifyResult verifyResult = new VerifyResult();
        extension.setSchedules("0");
        extension.setCases(0);
        extensionService.save(extension);
        return verifyResult;
    }

    @PutMapping
    public VerifyResult update(Extension extension){
        VerifyResult verifyResult = new VerifyResult();
        extensionService.update(extension);
        return verifyResult;
    }


    @DeleteMapping("/{id}")
    public VerifyResult delete(@PathVariable Integer id){
        VerifyResult verifyResult = new VerifyResult();
        extensionService.delete(id);
        return verifyResult;
    }

    /**
     *推广跟踪信息
     * @param param
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/track")
    public PageResult listTrack(Extension param, @RequestParam(defaultValue = "0") Integer pageNo, @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult<ExtensionVo> result = new PageResult();
        if(pageNo!=null&&pageSize!=null){
            PageHelper.startPage(pageNo, pageSize);
        }

        List<ExtensionVo> list = extensionService.queryListForTrack(param);

        PageInfo<ExtensionVo> pageInfo = new PageInfo<ExtensionVo>(list);
        result.setTotal(pageInfo.getTotal());
        result.setRows(pageInfo.getList());
        return result;
    }

    /**
     * 推广项目效果评估
     * @param param
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/assessment")
    public PageResult listAssessment(Extension param, @RequestParam(defaultValue = "0") Integer pageNo, @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult<Extension> result = new PageResult();
        if(pageNo!=null&&pageSize!=null){
            PageHelper.startPage(pageNo, pageSize);
        }

        List<Extension> list = extensionService.queryListForAssessment(param);

        PageInfo<Extension> pageInfo = new PageInfo<Extension>(list);
        result.setTotal(pageInfo.getTotal());
        result.setRows(pageInfo.getList());
        return result;
    }




}
